package net.display;

import javax.mail.Session;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;

import net.bo.KUtilisateur;
import net.ko.controller.KObjectController;
import net.ko.displays.KObjectDisplay;
import net.ko.http.controls.KCtrlHtml;
import net.ko.http.views.KFieldControl;
import net.ko.http.views.KHtmlElement;
import net.ko.http.views.KHtmlFieldControl;
import net.ko.kobject.KObject;
import net.ko.types.HtmlControlType;

public class DisplayDemande extends KObjectDisplay {

	@Override
	public KFieldControl getControl(KObject ko, String memberName,
			KObjectController koc, HttpServletRequest request) {
		KFieldControl result= super.getControl(ko, memberName, koc, request);
		
		koc.setValidatorClassName("net.controller.KValidateDemande");
		koc.getFieldController("description").setValidateMethodName("validateDescription");
		
		
		HttpSession session= request.getSession();
		KUtilisateur user = (KUtilisateur) session.getAttribute("activeUser");
		if("idTypeDemande".equals(memberName)){
			result.setValue("1");
			result.setCaption("");
		}
		if("dateDemande".equals(memberName)){
			result.setCaption("Date d'inscription");
			result.setFieldType(HtmlControlType.khcReadOnlyText);
		}
		
		if("user".equals(memberName)){
			result=new KHtmlFieldControl("", user.getId()+"", "idUtilisateur", "idUtilisateur", HtmlControlType.khcHidden);
		}
		
		
		if("description".equals(memberName)){
			result.setCaption("Motivations :");
			((KHtmlFieldControl)result).setOptions("style='margin: 2px; width: 299px; height: 90px' spellcheck='true';");
		}
		if("userName".equals(memberName)){
			result=new KCtrlHtml("<h1>"+user.getLogin()+"</h1>");
		}
		
	
		return result;
	}

}
